/**
 * Created by Administrator on 2018/6/1.
 */
$(function () {

    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }


    $("#sub").click(function () {

        /**
         * 一般网络请求使用ajax
         * $.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

         */

        $.ajax({
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            type: 'POST',
            url: "/new",
            data: JSON.stringify({
                articleName: $("#name").val(),
                articleContent: editor.txt.text(),
                authorName: getCookie("userName")
            }),
            success: function (data) {
                if (data != null) {


                    window.location.href = "/user-paper.html?userName=" + getCookie("userName");
                    //window.location.href = "/user-paper.html?userName="+$("#name").val();
                }
                else {
                    alert("保存出错！");
                }
            },
            contentType: "application/json; charset=utf-8"
        });
    });

});


